package avicit.bdp.dgs.qa.service.algo.raw.data.pcm.entity;

import cn.hutool.core.util.NumberUtil;

import java.text.DecimalFormat;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-11-01
 * @类说明：PcmTime
 * @修改记录：
 * @注意事项：
 * @主要功能：时间
 */
public class PcmTime {
    public static DecimalFormat DF = new DecimalFormat("#");
    public int hour;
    public int minute;
    public int second;
    public double ms;

    public PcmTime(int hour, int minute, int second, double ms) {
        this.hour = hour;
        this.minute = minute;
        this.second = second;
        this.ms = ms;
    }

    public PcmTime addMS(double inputMS) {
        this.ms += inputMS;
        checkTime();

        return this;
    }

    private void checkTime() {
        if (this.ms >= 1000) {
            this.ms = this.ms - 1000;
            this.second++;
        }
        if (this.second >= 60) {
            this.second = this.second - 60;
            this.minute++;
        }
        if (this.minute >= 60) {
            this.minute = this.minute - 60;
            this.hour++;
        }
        if (this.hour >= 24) {
            this.hour = this.hour - 24;
        }
    }

    public long getTime() {
        return (this.hour * 60 * 60 + this.minute * 60 + this.second) * 1000 + NumberUtil.round(this.ms, 1).longValue();
    }

    @Override
    public String toString() {
        return this.hour + ":" + this.minute + ":" + this.second + ":" + NumberUtil.round(this.ms, 1);
    }
}
